package cc.vv.btpartyjob.partymanager.delegate

import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.util.ColorUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.adapter.WorkTeamListAdapter
import cc.vv.btpartyjob.partymanager.moudel.bean.StreetActivitiesObj
import cc.vv.btpartyjob.partymanager.moudel.bean.TeamWorkObj
import cc.vv.mvp.delegate.BaseAppDelegate
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 工作队托管类
 * Created by Chen.qi on 2018/10/24.
 */
class WorkTeamActivityDelegate : BaseAppDelegate() {

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_community_activities
    }

    /**设置标题title*/
    fun setTopBarTitle(topBarTitle: String) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_aca_topBar)
        titleBar?.setTitle(topBarTitle)
        titleBar?.rl_ljtb_right_layout?.visibility = View.GONE

    }


    /**设置标题右边按钮点击事件*/
    fun setTitleBackBtnOnClick(event: BaseTopBarView.EventInterface) {
        val titleBar = getView<BaseTopBarView>(R.id.btv_aca_topBar)
        titleBar?.setEventInterface(event)
    }

    /**
     * 设置刷新监听
     */
    fun bindRefreshListener(listener: SwipeRefreshLayout.OnRefreshListener) {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_aca_swipeServiceActivities)
        refresh?.setOnRefreshListener(listener)
        refresh?.setColorSchemeColors(ColorUtil.setBCColor(R.color.color_FA555C))
    }

    /**
     * 设置刷新停止
     */
    fun stopRefreshing() {
        val refresh = getView<SwipeRefreshLayout>(R.id.srl_aca_swipeServiceActivities)
        refresh?.isRefreshing = false
    }

    /**
     * 设置加载更多监听
     */
    fun bindLoadMore(mAdapter: WorkTeamListAdapter?, loadMoreListener: BaseQuickAdapter.RequestLoadMoreListener) {
        val recyclerView = getView<RecyclerView>(R.id.rv_aStar_newsList)
        if (null != recyclerView) {
            mAdapter?.setOnLoadMoreListener(loadMoreListener, recyclerView)
        }
    }


    /** 设置适配器*/
    fun setRecyclerViewAdapter(mAdapter: WorkTeamListAdapter?) {
        if (null != mAdapter) {
            val recyclerView = getView<RecyclerView>(R.id.rv_aca_communityActivities)
            recyclerView?.layoutManager = LinearLayoutManager(context)
            recyclerView?.adapter = mAdapter
        }
    }


    /** 数据适配器 */
    fun setAdapterData(mAdapter: WorkTeamListAdapter?, list: List<TeamWorkObj>?) {
        if (null != list) {
            mAdapter?.setNewData(list)
            if (list.isEmpty()) {
                showNoDataView(true)
            } else {
                showNoDataView(false)
            }
        } else {
            showNoDataView(true)
        }
    }


    /** 显示暂无数据缺省页 */
    private fun showNoDataView(isNoData: Boolean) {
        val noData = getView<TextView>(R.id.btv_aca_comNoData)
        if (isNoData) {
            noData?.visibility = View.VISIBLE
        } else {
            noData?.visibility = View.GONE
        }
    }
}